<template>
	<view class="content">
		<button @click="changeLanguage">切换语言</button>
		<button @click="$store.state.count++">++</button>
		<view>{{ $store.state.count }}</view>
		<u-button type="primary" text="首页" @click="goLogin"></u-button>
		<view class="text-area">
			<text class="title">{{ $t('page.login.title') }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {

		},
		methods: {
			changeLanguage() {
				uni.showActionSheet({
					itemList: [
						// this.$t('public.en'),
						// this.$t('public.zh-Hans'),
						// this.$t('public.es'),
						'English',
						'中文简体',
						'Español',
						// '中文繁体'
					],
					success: (res) => {
						//#ifdef  H5
						this.$router.go(0); //刷新页面，不然validate.js不好国际化
						//#endif
						//#ifdef  APP-PLUS
						uni.navigateTo({
							url: '/pages/user/Login/index' // 要刷新的页面路径
						});
						//#endif

						const language = [{
								text: '英文',
								code: 'en'
							},
							{
								text: '中文简体',
								code: 'zh-Hans'
							},
							{
								text: '西班牙语',
								code: 'es'
							},
							// {text:'中文繁体',code:'zh-Hant'},
						]
						this.curLanguage = language[res.tapIndex].text;
						// this.$store.commit('changeLanguage', language[res.tapIndex].code);
						uni.setStorage({
							key: 'language',
							data: language[res.tapIndex].code
						})
						this.$i18n.locale = language[res.tapIndex].code
						uni.setLocale(language[res.tapIndex]
							.code) //切换语言环境必须在this.$i18n.locale之后，否则app端会有意想不到的bug
					},
					fail: function(res) {}
				});
			},
			goLogin(){
				uni.switchTab({
					url: '/pages/home/home'
				});
			}
		}
	}
</script>

<style lang="scss">
	
</style>